package com.example.hrmsaas.system.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

public class CreateJwtTest {

    /***
     * 生成token串
     * @param Str
     * @param salt
     * @return
     */
    public String CreateJwt(String id,String Str,String salt)
    {
        JwtBuilder jwtBuilder = Jwts.builder().setId(id).setSubject(Str)
                .setIssuedAt(new Date()).signWith(SignatureAlgorithm.HS256,salt)
                .claim("CompanyId","123")
                .claim("CompanyName","测试公司");

        return jwtBuilder.compact();
    }

    public Claims analysis(String token,String salt){

        return Jwts.parser().setSigningKey(salt).parseClaimsJws(token).getBody();
    }

}
